%% Create Adaptive Schedule (Rig1)

% File Name | warning: file will be overwritten without prompting
sch = 'Adaptive_NB_DELAY_schedule.mat';
FN = ['C:\Behavior\NB Detection\Schedule Files\' sch];

clear schedule trialdef

%% parameter tags

% for RPvds direct access
schedule.writeparams = {'gap_duration','trial_type','NoiseHP','NoiseLP', ...
    'NoiseAmp~1','NoiseAmp~2','dBSPL','stim_delay'};
schedule.writemodule = ones(size(schedule.writeparams));
schedule.readparams  = {'trial_index','response','trial_state'};
schedule.readmodule  = ones(size(schedule.readparams));
schedule.nreps       = 10;
schedule.randomize   = true;
schedule.schedule    = sch;

%% Check yo' self
if length(schedule.writeparams) ~= length(schedule.writemodule)
	error('write params/module lengths differ!');
end

if length(schedule.readparams) ~= length(schedule.readmodule)
	error('read params/module lengths differ!');
end

%% Initialize with first trial
schedule.trials = [50,0,2000,43000,0.171988734,0.156675107,80,750];


%% Adaptive trials
schedule.AdaptiveTrials.increment =  250; % in milliseconds
schedule.AdaptiveTrials.decrement = -250;
schedule.AdaptiveTrials.incrafter = 3; % trials
schedule.AdaptiveTrials.decrafter = 3;
schedule.AdaptiveTrials.min       = 750; % in milliseconds
schedule.AdaptiveTrials.max       = 7000;
schedule.AdaptiveTrials.parameter = 'stim_delay';



%% Save

save(FN,'schedule');

















